package com.Jhu1.controller;

import com.Jhu1.entity.Store;
import com.Jhu1.service.MerchantService;
import com.Jhu1.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/merchant")
public class MerchantController {
    @Autowired
    private MerchantService merchantService;
    
    @GetMapping("/all")
    public Result<List<Store>> getMerchantAll() {
        List<Store> merchants = merchantService.getMerchantAll();
        return Result.success(merchants);
    }
    
    @PostMapping("/add")
    public Result<?> addMerchant(@RequestBody Store merchant) {
        merchantService.add(merchant);
        return Result.success();
    }
    
    @GetMapping("/myStore")
    public Result<Store> myStore() {
        return Result.success(merchantService.myStore());
    }
    
    @PatchMapping("/update")
    public Result<?> update(@RequestBody Store store) {
        merchantService.update(store);
        return Result.success();
    }
    
    @DeleteMapping("/delete")
    public Result<?> deleteMerchant(@RequestParam("id") Integer id) {
        merchantService.delete(id);
        return Result.success();
    }
}
